package com.fly_fox;

import com.fly_fox.dao.TaskItemDao;
import com.fly_fox.dto.TaskGroupDto;
import com.fly_fox.entity.TaskItem;
import com.fly_fox.service.TaskItemService;
import com.fly_fox.util.JdbcUtil;
import com.fly_fox.util.PathUtils;
import com.fly_fox.util.SafeProperties;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.util.Scanner;

public class Use {

    public static void main(String[] args) {
        //  加载数据
        Path jdbcPath= PathUtils.getResPath("jdbc.properties");
        JdbcUtil.loadConfig(jdbcPath);

        TaskItemService service=new TaskItemService();

        Scanner enter = new Scanner(System.in);
        String dateStr=LocalDate.now().toString();
        Path path;
        //输入的是int类型
        while (true) {
            System.out.println("请输入你的清单名称(yml格式):");
            String line = enter.nextLine();
            //enter.close();
            Path rootDir=PathUtils.getResRootPath();
            //System.out.println(rootDir);
            path= PathUtils.append(rootDir,line);
            if(Files.exists(path)){
               break;
            }
            System.out.println("该路径不存在:"+path.toAbsolutePath()+",请传入正确的路径");
        }

        System.out.println("是否查看指定日期的复习分组(是的话输入日期 否则默认为今天)");
        String line=enter.nextLine();
        if(!line.equals("")){
            dateStr=line;
        }
        enter.close();


        //service.loadDefaultDataYaml();
        service.loadDataYaml(path);
        TaskGroupDto dto = service.getGroupName(dateStr);
        TaskItem taskItem = service.random(dto);
        System.out.println(dateStr+"日的复习分组为:"+dto.getTitle());
        System.out.println(dateStr+"日的复习分组具体内容为:"+taskItem.getItemName());

    }

}
